package com.authentications.filter.login;

import com.authentications.filter.login.incomplete.GeneralLogin;
import com.authentications.utils.JWTUtils;
import com.authentications.utils.SpringContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName DefaultLoginController
 * @Author xiezhuocai
 * @Description TODO
 * @Date 2021/12/15 16:56
 */
@RestController
@RequestMapping("/login")
public class DefaultLoginController {

    private Logger logger = LoggerFactory.getLogger(DefaultLoginController.class);

    //登录接口
    @PostMapping
    public String login(@RequestBody String pramStr) {
        logger.info("/login入参:"+pramStr);
        GeneralLogin login = SpringContextUtils.getBean(GeneralLogin.class);
        if (login == null) return null;
        String  result = login.login(pramStr);
        logger.info("加密数据:"+pramStr);
        if (StringUtils.isEmpty(result)) return null;
        return JWTUtils.createToken(result);
    }
}
